package likou;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/18 07:54
 */
public class _20 {
    public static void main(String[] args) {
        System.out.println(isValid("}"));
    }
    public static boolean isValid(String s) {
        Deque<Character> deque = new LinkedList<>();
        char[] scs = s.toCharArray();
        for (char sc : scs) {
            if (sc == '(' || sc == '[' || sc == '{') {
                deque.offerLast(sc);
                continue;
            }
            if (deque.size()>0){
                Character character = deque.pollLast();
                if ((sc == ')' && character == '(') || (sc == ']' && character == '[') || sc == '}' && character == '{') {
                    continue;
                }
            }
            return false;
        }
        return deque.size() == 0;
    }
}
